package com.action.log;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.beans.log.LogInfo;
import com.business.log.LogInfoBus;
import com.config.SystemGlobals;
import com.util.TextTools;

public class EditLog extends HttpServlet {

	private static final long serialVersionUID = 1L;
	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String contentType = SystemGlobals.getValue("contentType");
		PrintWriter out = response.getWriter();
		response.setContentType(contentType);
		String logNo = request.getParameter("logno");
		String title = request.getParameter("title");
		String content = request.getParameter("content");
		String isQuote = request.getParameter("isquote");
		String isShow = request.getParameter("isshow");
		String logAuthor = request.getParameter("logauthor");
		String logCategory = request.getParameter("logcategory");
		String logIntro = request.getParameter("intro");
		String logTag=request.getParameter("logtag");
		logIntro = TextTools.txt2html(logIntro);
		LogInfo loginfo = new LogInfo();
		loginfo.setLogIntro(logIntro);
		loginfo.setLogCategory(logCategory);
		loginfo.setIsShow(isShow);
		loginfo.setLogAuthor(logAuthor);
		loginfo.setLogContent(content);
		loginfo.setLogTag(logTag);
		Date date = new Date();
		Timestamp nowsTime = new Timestamp(date.getTime());
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String logQuoteId = request.getParameter("logquoteid");
		if (isQuote == null || isQuote.equals("")) {
			isQuote = "0";
			logQuoteId = "0";

		}
		loginfo.setIsQuote(isQuote);
		loginfo.setLogPostTime(sdf.format(nowsTime));
		loginfo.setLogTitle(title);
		String logtypeId = request.getParameter("logtypeid");
		loginfo.setLogtypeId(logtypeId);
		loginfo.setReplynum("0");
		loginfo.setLogQuotenums("0");
		loginfo.setViewnums("0");
		loginfo.setLogQuoteId(logQuoteId);
		LogInfoBus lis = new LogInfoBus();
		lis.updateLog(loginfo, logNo);
		out
				.print("<script>alert(\"您成功修改了日志内容\");window.location=\"user/log/addlog.jsp\";</script>");
		out.close();
	}

}
